import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:localStorage.getItem('token')?localStorage.getItem('token'):'',
    addFromInfo:{
      goods_name:'',
      goods_cat:'',
      goods_price:'',
      goods_number:'',
      goods_weight:'',
      goods_introduce:'',
      pics:[],
      attrs:[]
    }
  },
  mutations: {
    setToken(state,playlod){
      state.token=playlod.token
      localStorage.setItem('token',playlod.token)
    },
    delToken(state){
      state.token=''
        localStorage.removeItem('token')
    },
    //获得商品信息表单的数据
    setGoodsInfo(state,playlod){
          state.addFromInfo.goods_name=playlod.goods_name
          state.addFromInfo.goods_cat=playlod.goods_cat
          state.addFromInfo.goods_price=playlod.goods_price
          state.addFromInfo.goods_number=playlod.goods_price
          state.addFromInfo.goods_weight=playlod.goods_weight
    },
    setGoodsPics(state,playlod){
      console.log(playlod);
      playlod.pics.forEach(element=>{
        const obj={}
        obj.pic=element.pic
        state.addFromInfo.pics.push(obj)
      })

    },
    setGoodsIntroduce(state,playlod){
      state.addFromInfo.goods_introduce=playlod.goodsIntroduce
    },
    setGoodsParams(state,playlod){
          state.addFromInfo.attrs=playlod.attrs
    }
  },
  actions: {
  },
  modules: {
  }
})
